package libro.cap04;

import java.sql.SQLException;
import java.util.Collection;
import java.util.Scanner;

public class Cliente {

	public static void main(String[] args) throws SQLException {

		Facade facade = new Facade();
		Collection<DeptDTO> collDepts = facade.obtenerDepartamento();
		// muestro los departamentos
		_mostrarDepartamentos(collDepts);
		// ingrese por teclado un depto
		Scanner scanner = new Scanner(System.in);
		int deptno = scanner.nextInt();

		Collection<EmpDTO> collEmps = facade.obtenerEmpleados(deptno);
		//muestro los empleados
		_mostrarEmpleados(collEmps, deptno);
		
	}


	private static void _mostrarDepartamentos(Collection<DeptDTO> collDepts) {
		
		System.out.println("Departamentos");
		System.out.println("--------------");
		for(DeptDTO dto : collDepts){
			System.out.print("| "+dto.getDeptno()+"\t");
			System.out.print("| "+dto.getDname()+"\t");
			System.out.println("| "+dto.getLoc()+"\t");
		}
		System.out.println("<---------------");
		System.out.println("Ingrese departamento: ");
	}
	
	
	private static void _mostrarEmpleados(Collection<EmpDTO> collEmps,int deptno) {
		
		System.out.println("Empleados del depto "+deptno);
		System.out.println("------------->");
		for(EmpDTO dto : collEmps){
			System.out.print("| "+dto.getEmpno()+"\t");
			System.out.print("| "+dto.getEname()+"\t");
			System.out.println("| "+dto.getHiredate()+"\t");
			
		}
		
		System.out.println("<---------------------");
	}
}
